<?php
class Lunchbox extends MY_Controller {

	function  __construct(){

		parent::__construct();
		if(!$this->admin) {
			redirect('admin990/admin');

		}

	}

	function index()
	{
		$data['files'] = get_dir_file_info('lunch_pdf', $top_level_only = TRUE);
		$data['cartes'] = get_dir_file_info('carte_pdf', $top_level_only = TRUE);
		$data['title'] = 'Lunch Box';
		$this->load->view('admin/header',$data);
		$this->load->view('admin/lunchbox');
	}


	function do_upload()
	{
		if($_POST['type'] == 1 ){

			$config['upload_path'] = './lunch_pdf/';
			$config['allowed_types'] = 'pdf';
			$config['file_name'] = "neufneugdragon_lunchbox";
			$config['overwrite'] = TRUE;

			$this->load->library('upload', $config);

			if ( ! $this->upload->do_upload())
			{
				$data['error'] = array('error' => $this->upload->display_errors());

			}
			else
			{
				$data['msg'] = 'Votre fichier a été enregistré!';

			}
		}elseif($_POST['type'] == 2){
			$config['upload_path'] = './carte_pdf/';
			$config['allowed_types'] = 'pdf';
			$config['file_name'] = "neufneufdragon_carte";
			$config['overwrite'] = TRUE;

			$this->load->library('upload', $config);

			if ( ! $this->upload->do_upload())
			{
				$data['error'] = array('error' => $this->upload->display_errors());

			}
			else
			{
				$data['msg'] = 'Votre carte a été enregistré!';

			}
		}
		$data['files'] = get_dir_file_info('lunch_pdf', $top_level_only = TRUE);
		$data['cartes'] = get_dir_file_info('carte_pdf', $top_level_only = TRUE);
		$data['title'] = 'Lunch Box';
		$this->load->view('admin/header',$data);
		$this->load->view('admin/lunchbox_upload');

	}

	function delete()
	{
		if($_GET)
		{
			$file = get_filenames($_GET['director']);
			if($file){
			delete_files($_GET['director']);
			}
			redirect('admin990/lunchbox');
		}
		
	}

}